package com.kb.dto.gc;

import com.alibaba.fastjson.annotation.JSONField;
import com.kb.enums.FieldEnum;
import lombok.Data;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class TemplateFields {
    private String key0;
    private String key1;
    private String key2;
    private String key3;
    private String key4;
    private String key5;
    private String key6;
    private String key7;
    private String key8;
    private String key9;
    private String key10;
    private String key11;
    private String key12;
    private String key13;
    private String key14;
    private String key15;
    private String key16;
    private String key17;
    private String key18;
    private String key19;
    private String key20;
    private String key21;
    private String key22;
    private String key23;
    private String key24;
    private String key25;
    private String key26;
    private String key27;
    private String key28;
    private String key29;
    private String key30;
    private String key31;
    private String key32;
    private String key33;
    private String key34;
    private String key35;

    // 添加构造函数
//    public TemplateFields(String name, String enName, String value) {
//        this.name = name;
//        this.enName = enName;
//        this.value = value;
//    }
    @JSONField(serialize = false)
    public List<Map<String, Object>> getNonEmptyFieldsAsList() {
        List<Map<String, Object>> resultList = new ArrayList<>();
        Field[] fields = this.getClass().getDeclaredFields();
        //key转成对应的中文名
        for (Field field : fields) {
            try {
                field.setAccessible(true);
                Object value = field.get(this);
                if (value != null) {
                    String fieldName = field.getName();
                    String name = FieldEnum.getNameByKey(fieldName);
                    Map<String, Object> map = new HashMap<>();
                    map.put("key", fieldName);
                    map.put("value", name);
                    resultList.add(map);
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }

        return resultList;
    }
}
